package cloudInformation.controller;

import cloudEntity.entity.dorm.SmartDormEntity;
import cloudEntity.leftJoin.DormPersonLeftJoin;
import cloudEntity.utils.ResultUtils;
import cloudEntity.vo.dorm.SmartDormPersonDesVO;
import cloudInformation.mapper.SmartDormMapper;
import cloudInformation.service.SmartDormService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @program: Smart School
 * @ClassName DormController
 * @description: 宿舍控制器 -> 依附于 楼层控制器
 * @author: 陈智博
 * @create: 2025-05-17 10:18
 * @Version 1.0
 **/
@RestController
@RequestMapping("/dorm")
@Tag(name = "宿舍控制器")
public class DormController {

    @Autowired
    private SmartDormService smartDormService;

    @Autowired
    private SmartDormMapper smartDormMapper;

    @Operation(summary = "根据楼层id获取楼层里面的所有宿舍信息")
    @Parameter(name = "ids",description = "楼层id",required = true)
    @RequestMapping(method = RequestMethod.GET,value = "/get/byIds")
    public ResultUtils GetDormByFloorIds(@RequestParam("ids") String ids)
    {
       List<SmartDormEntity> DormList =  smartDormService.GetDormByIds(ids);
       return ResultUtils.success(DormList);
    }

    @Operation(summary = "根据宿舍id获取宿舍有哪些人")
    @Parameter(name = "ids",description = "宿舍id",required = true)
    @RequestMapping(method = RequestMethod.GET,value = "/get/dorm/person")
    public ResultUtils GetDormPersonByIds(@RequestParam("ids") String ids){
        List<DormPersonLeftJoin> dormPersonLeftJoins = smartDormService.GetDormPersonByIds(ids);
        return ResultUtils.success(dormPersonLeftJoins);
    }

    @Operation(summary = "根据个人的uid获取你宿舍扣分的信息")
    @Parameter(name = "ids",description = "用户uid",required = true)
    @RequestMapping(method = RequestMethod.GET,value = "/get/dorm/des")
    public ResultUtils GetPersonByDormAndDesByIds(@RequestParam("ids") String ids)
    {
        List<SmartDormPersonDesVO> list =  smartDormService.GetDormPersonDes(ids);
        return ResultUtils.success(list);
    }

    @Operation(summary = "删除宿舍扣分信息")
    @Parameter(name = "ids",description = "宿舍扣分ids",required = true)
    @RequestMapping(method = RequestMethod.DELETE,value = "/delete")
    public ResultUtils DeletePersonSubDesByIds(@RequestParam("ids") String ids)
    {
        Integer i = smartDormMapper.deleteSubPersonByIds(ids);
        if(i>0)
        {
            return ResultUtils.success("删除记录成功!");
        }
        return ResultUtils.failed("删除记录失败!");
    }

}
